﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectStorageLib.Project
{
    public class ProjectInapplicability : DatabaseEntities
    {
        #region Constructor and Destructor

        public ProjectInapplicability()
            : base()
        { }

        protected override void Dispose(bool flag)
        {

        }

        #endregion Constructor and Destructor

        public List<InapplicabilePractice> GetInapplicabilePractice(decimal IdProject)
        {
            try
            {
                return (from inapp in ent.FactorsInapplicability
                        where inapp.FactorScales.ProjectFactorScale.Where(prFc => prFc.ProjectID == IdProject).Count() > 0
                        group inapp by new { inapp.AgilePractices.Name } into grp
                        select new InapplicabilePractice
                        {
                            Practice = grp.Key.Name,
                            Value = grp.Max(gr => gr.value)
                        }).Where(vl => vl.Value > 0).OrderByDescending(vl => vl.Value).ToList();
                
            }
            catch (Exception)
            {
                throw;
            }
        }
    }

    public class InapplicabilePractice
    {
        public string Practice { get; set; }
        public int Value { get; set; }
    }
}
